<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>管理员登录</title>
	<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="/css/main.css">
    <style>
        .row{
				margin-top: 100px;
				margin-right: 0px; 
    	}
		div[role=alert]{
			display:none;
		}
    </style>
</head>

<body>
	<div class="loginbgbox">
		<div class="loginbgimg">
			<span  style="background-image: url(/img/login_bg01.png);"></span>
		</div>
		<div class="loginhouse">
			<img class="lh_box" src="/img/login_house.png"/>
			<img class="lh_box" src="/img/login_house.png"/>
			<img class="lh_box" src="/img/login_house.png"/>
		</div>
	    <div class="row">
	    	<div class="login_logo"><img src="/img/logo.png" alt=""></div>
	        <div class="col-md-3 col-md-offset-5 loginbox">
	        	<div class="login_title"><b>欢迎登录</b>柚备管理平台</div>
	            <div class="alert alert-danger" role="alert"></div>
	            <form class="form-horizontal">
	                <div class="form-group">
	                    <!-- <label for="inputEmail3" class="col-sm-2 control-label">用户名称</label> -->
	                    <div class="col-sm-12">
	                        <input type="text" class="form-control" name="name" id="username" placeholder="用户名称">
	                    </div>
	                </div>
	                <div class="form-group">
	                    <!-- <label for="inputPassword3" class="col-sm-2 control-label">用户密码</label> -->
	                    <div class="col-sm-12">
	                        <input type="password" class="form-control" name="password" id="password" placeholder="用户密码" onkeydown="KeyDown()">
	                    </div>
	                </div>
	                <div class="form-group">
	                    <div class="col-sm-12">
	                        <button type="button" class="btn btn-default loginbtn" onclick="login()">登录</button>
	                    </div>
	                </div>
	            </form>
	        </div>
	    </div>
	</div>
</body>

</html>
    <script type="text/javascript">
	    function KeyDown() {
	        if (window.event.keyCode == 13) {
	            login()
	        }
	    }

	    function login() {
	        var user = document.getElementById("username").value;
	        var password = document.getElementById("password").value;
	        if (user && password) {
	            $.ajax({
					url:"/home/login",
					data:{username:user,password:password},
					type:"post",
					datatype:"json",
					success:function(res){
						if (res.success == 0) {
							window.location = "/home"
						}else{
							alert(res.msg)
						}
					}
				})
	            
	        } else {
	            $("div[role=alert]").css("display", "block")
	            $("div[role=alert]").text("请输入用户名或密码");
	        }
	    }

	    window.onload=function(){
	    	var _loginbgbox=document.getElementsByClassName('loginbgbox')[0]
	    	var H=document.documentElement.clientHeight
	    	_loginbgbox.style.height = H +'px'
	    	var _loginhouse=document.getElementsByClassName('loginhouse')[0]
	    	var _lh_box=document.getElementsByClassName('lh_box')
	    	_loginhouse.style.width = _lh_box.length * 3336 +'px'
	    }
    </script>